package com.money.controller;

import com.money.entity.User;
import com.money.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/doLogin")
    public String userLogin(User user, HttpSession session, Model model) {
        User user1 = userService.userLogin(user);
        if (user1 != null) {
            session.setAttribute("user", user1);
            //如果user1不为空则跳转到查询页面，否则回到登录界面并提示用户名或密码错误
            return "redirect:/selectBooks";
        } else {
            model.addAttribute("loginError", 1);
            return "login";
        }

    }
}
